//
//  VideoInfoViewController.m
//  HorizonLight
//
//  Created by lanou on 15/9/19.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "VideoInfoViewController.h"
#import "VideoInfoView.h"

#import "MediaViewController.h"

@interface VideoInfoViewController ()<UIAlertViewDelegate,UIScrollViewDelegate>

@property (nonatomic, strong) VideoInfoView *videoInfoView;


@end

@implementation VideoInfoViewController
{
    UIAlertView *alertView;
    
}

#pragma mark-----设置
- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置navigationController的透明度
    self.navigationController.navigationBar.translucent = NO;
    //隐藏下一界面的UITabBar
    [self.tabBarController.tabBar setHidden:YES];
    //初始化UIView
    self.videoInfoView = [[VideoInfoView alloc]initWithFrame:kBounds taget:self action:@selector(settingClick) array:self.dataArray indexPath:_indexPath];
    //获取model里德数据
    [self.videoInfoView setValueWithModel:self.videoInfoModel array:self.dataArray];
    //三个按钮的点击方法
    [self.videoInfoView.clickPraiseButton addTarget:self action:@selector(click:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.videoInfoView.shareButton addTarget:self action:@selector(shareClick:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.videoInfoView.cacheButton addTarget:self action:@selector(cacheClick:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.view addSubview:self.videoInfoView];
    
}





#pragma mark-----隐藏TabBar的方法
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self.hidesBottomBarWhenPushed = YES;
    return self;
}

#pragma mark-----ImageView的点击方法
- (void)settingClick
{
    NSLog(@"即将进入播放");
    MediaViewController *mediaVC = [[MediaViewController alloc] init];
    mediaVC.mediaUrl = self.videoInfoModel.highUrl;
    mediaVC.headline = self.videoInfoModel.title;
    [self presentViewController:mediaVC animated:YES completion:nil];
}

#pragma mark-----Click  点赞
- (void)click:(UIButton *)button
{
    button.selected = !button.selected;
    if (button.selected == YES)
    {
        //设置点击第一次完成收藏
        [button setBackgroundImage:[UIImage imageNamed:@"FontAwesome_f004(0)_40"] forState:(UIControlStateSelected)];
       self.videoInfoView.clickPraiseLabel.text = [NSString stringWithFormat:@"%lu", self.videoInfoModel.collectionCount + 1];
        //添加一个弹窗,  显示是否收藏成功
        alertView = [[UIAlertView alloc]initWithTitle:@"已收藏成功" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
        //设置弹窗是自动消失的
        [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(view:) userInfo:nil repeats:NO];
        [alertView show];
    }else
    {
        //当点击第二次取消收藏
        [button setBackgroundImage:[UIImage imageNamed:@"FontAwesome_f08a(0)_48"] forState:(UIControlStateNormal)];
        self.videoInfoView.clickPraiseLabel.text = [NSString stringWithFormat:@"%lu", self.videoInfoModel.collectionCount];
    }
}
- (void)view:(NSTimer *)timer
{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
}


#pragma mark-----shareClick 分享
- (void)shareClick:(UIButton *)button
{
    button.selected = !button.selected;
    if (button.selected == YES)
    {
       self.videoInfoView.shareLabel.text = [NSString stringWithFormat:@"%lu", self.videoInfoModel.shareCount + 1];
    }else
    {
        
        self.videoInfoView.shareLabel.text = [NSString stringWithFormat:@"%lu",self.videoInfoModel.shareCount];
    }
}

#pragma mark-----cacheClick 缓存
- (void)cacheClick:(UIButton *)button
{
    button.selected = !button.selected;
    if (button.selected == YES) {
        self.videoInfoView.cacheLabel.text = @"没实";
    }else
    {
        self.videoInfoView.cacheLabel.text = @"缓存";
    }
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
